package restaurant;

import java.util.ArrayList;

/**
 * Represents a waitperson. This class contains information about a waitperson.
 * 
 * @author Odessa
 */

public class Waitperson
{

	/** The waitperson device. */
	private WaitpersonUI device;

	/** The waitperson's ID number. */
	private int id;

	/** The waitperson's first name. */
	private String first;

	/** The waitperson's last name. */
	private String last;

	/** List of this waitperson's pick up times. */
	private ArrayList<Integer> pickupTimes;



	/**
	 * Instantiates a newly created waitperson.
	 * 
	 * @param id the id number of the waitperson to be created. Cannot be null.
	 * @param first the first name of this waitperson.
	 * @param last the last name of this waitperson.
	 */
	public Waitperson(int id, String first, String last) {
		this.id = id;
		this.first = first;
		this.last = last;
		pickupTimes = new ArrayList<Integer>();
		device = new WaitpersonUI();
	}



	/**
	 * Gets this waitperson's ID number. The ID number is used to uniquely
	 * identify a waitperson.
	 * 
	 * @return the id number of this waitperson.
	 */
	public int getId()
	{
		return id;
	}



	/**
	 * Gets this waitperson's first name.
	 * 
	 * @return the waitperson's first name.
	 */
	public String getFirst()
	{
		return first;
	}



	/**
	 * Gets this waitperson's last name.
	 * 
	 * @return the waitperson's last name.
	 */
	public String getLast()
	{
		return last;
	}



	/**
	 * Returns this waitperson's average pick up time. Calls
	 * <code> calcAvgPickupTime </code> to calculate the average.
	 * 
	 * @return the average pick up time of this waitperson.
	 */
	public float getAvgPickupTime()
	{
		return calcAvgPickupTime();
	}



	/**
	 * Calculates a waitperson's average pick up time. Uses the list of this
	 * waitperson's pick up time to calculate the average.
	 * 
	 * @return the average pick up time for this waitperson.
	 */
	private float calcAvgPickupTime()
	{
		int num;
		int sum = 0;
		float avg;

		num = pickupTimes.size();

		for (int i = 0; i < num; i++)
			sum = sum + pickupTimes.get(i);

		avg = sum / num;

		return avg;
	}



	/**
	 * Adds the new pick up time to the list of this waitperson's pickup times.
	 * 
	 * @param time the new pick up time to be added to the list.
	 */
	public void addPickupTime(int time)
	{
		pickupTimes.add(time);
	}
}
